package cn.io.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @author summit
 * @since 2022/5/11 10:36
 */
public class TcpServer {

	public static void main(String[] args) throws IOException {
		ServerSocket server = new ServerSocket(9000);

		while (true) {
			System.out.println("等待接收==========");
			Socket socket = server.accept();
			InputStream is = socket.getInputStream();
			byte[] b = new byte[10];
			is.read(b);

			System.out.println(String.format("收到来自[%s]客户端信息：=> %s", socket.getInetAddress().getHostAddress(), new String(b)));
			OutputStream outputStream = socket.getOutputStream();
			outputStream.write("回复你:".getBytes());
			socket.close();
		}
	}
}
